<?php

namespace app\common\model;

use think\Db;
use think\Model;

class Zhifa extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'add_time';
    protected $updateTime = 'edittime';
    // 追加属性
    protected $append = ['image'];

    /**
     * 获取用户信息
     * @param int $user_id 用户id
     */
    public static function user_info(int $user_id)
    {
        $where = "id = {$user_id}";
        $info = self::where($where)->field("*")->find()->toArray();
        $cleaned_data = array_map(function ($value) {
            return ($value === null) ? "" : $value;
        }, $info);
        return $cleaned_data;
    }

    /**
     * 登录方法
     * @param string $tel
     * @param string $password
     */
    public static function login($tel,$password)
    {
        $where['tel']=$tel;
        $where['is_del']='0';
        $info = self::where($where)->find();
        
        return $info;
        
    }

    /**
     * 获取个人头像
     */
    public function getImageAttr($value)
    {
        if($value){
            return splicing_domain($value);
        }else{
            return "";
        }
    }


    public function getIdCard1ImageAttr($value)
    {
        if($value){
            return splicing_domain($value);
        }else{
            return "";
        }
    }

    public function getIdCard2ImageAttr($value)
    {
        if($value){
            return splicing_domain($value);
        }else{
            return "";
        }
    }

    /**
     * 获取头像
     * @param string $value
     * @param array  $data
     * @return string
     */
    public function getAvatarAttr($value, $data)
    {
        if (!$value) {
            //如果不需要启用首字母头像，请使用
            //$value = '/assets/img/avatar.png';
            $value = letter_avatar($data['nickname']);
        }
        return $value;
    }

    /**
     * 获取会员的组别
     */
    public function getGroupAttr($value, $data)
    {
        //return UserGroup::get($data['group_id']);
    }


   

}
